package R.Service;

import R.Dao.SickDao;
import R.Entity.Diagnosis;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "SickShowAllServlet", value = "/SickShowAll")
public class SickShowAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        List<Diagnosis> list = SickDao.showAll();
        if (list != null) {
            request.setAttribute("SickList", list);//在请求过程中绑定
            request.getRequestDispatcher("/R/sickShowAll.jsp").forward(request, response);//请求转发
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        /*HttpSession session = request.getSession();
        if (session.getAttribute("loginName")==null){
            response.sendRedirect("/Test/dormLogin.jsp");
        }*/
        String card_number = request.getParameter("card_number");//就诊卡号
        String record_number = request.getParameter("record_number");//病历编号
        String patient_name = request.getParameter("patient_name");//病人姓名
        //创建实体类
        Diagnosis d = new Diagnosis();
        d.setCard_number(card_number);
        d.setRecord_number(record_number);
        d.setPatient_name(patient_name);
        if (!card_number.equals("") && !record_number.equals("") && !patient_name.equals("")) {
            List<Diagnosis> list = SickDao.ChaXun(d);
            if (list != null) {
                request.setAttribute("SickList", list);//在请求过程中绑定
                request.getRequestDispatcher("/R/sickShowAll.jsp").forward(request, response);//请求转发
            }
        } else {
            List<Diagnosis> list = SickDao.showAll();
            if (list != null) {
                request.setAttribute("SickList", list);//在请求过程中绑定
                request.getRequestDispatcher("/R/sickShowAll.jsp").forward(request, response);//请求转发
            }
        }
    }
}
